import torch
import requests
from PIL import Image
import torch_npu
from torch_npu.contrib import transfer_to_npu
from diffusers import StableDiffusionDepth2ImgPipeline


torch.npu.set_compile_mode(jit_compile=False)


pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-2-depth",
).to("cuda")

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
init_image = Image.open(requests.get(url, stream=True).raw)
prompt = "two tigers"
n_prompt = "bad, deformed, ugly, bad anatomy"
image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=0.7).images[0]
image.save("./image.png")